home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / axpicker / modtltip.bas < prev    next >
Encoding:
BASIC Source File  |  1998-03-19  |  12.0 KB  |  245 lines

  1. Attribute VB_Name = "modToolTip"
  2. '*****************************************************************
  3. '
  4. '   POPUPCOMMAND CONTROL
  5. '
  6. '   This code and control is absolutely freeware!
  7. '
  8. '   You have a royalty-free right to use, modify, reproduce and distribute
  9. '   the source code and control (and/or any modified version) in any way
  10. '   you find useful, provided that you agree that the authors have no warranty,
  11. '   obligations or liability for any code distributed in this project group.
  12. '
  13. ' Copyright ⌐ 1998 by Geoff Glaze
  14. '
  15. '   (Some parts borrowed from Microsoft)
  16. '
  17. '*****************************************************************
  18.  
  19. '-------------------------------------------------------------------------
  20. 'This module is needed because it provides a WinProc used for subclassing.  Tooltips
  21. 'must be provided in this manner because VB5's tooltips for an intrinsic
  22. 'control does not work with the SetCapture API in use.  Also, VB's provided
  23. 'tooltip is container provided.  Therefore, if a control is used in a
  24. 'container that does not provide a tooltiptext property on the extender
  25. 'object, the tooltip would not be provided.  The tooltip in this control is
  26. 'provided regardless of the container hosting it.  The
  27. 'set capture is necessary to know precisely when the mouse moves over the control
  28. 'and then back off the control.
  29. '-------------------------------------------------------------------------
  30.  
  31. Option Explicit
  32.  
  33. Public Type TOOLINFO
  34.     cbSize As Long
  35.     uFlags As Long
  36.     hwnd As Long
  37.     uId As Long
  38.     rct As RECT
  39.     hinst As Long
  40.     lpszText As Long
  41. End Type
  42.  
  43. Public Type MSG
  44.     hwnd As Long
  45.     message As Long
  46.     wParam As Long
  47.     lParam As Long
  48.     Time As Long
  49.     pt As POINTAPI
  50. End Type
  51.  
  52. Public Type NMHDR
  53.     hwndFrom As Long
  54.     idfrom As Long
  55.     code As Long
  56. End Type
  57.  
  58. Public Type ToolTipText
  59.     hdr As NMHDR
  60.     lpszText As Long
  61.     szText As String * 80
  62.     hinst As Long
  63.     uFlags As Long
  64. End Type
  65.  
  66. 'Public Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
  67. 'Public Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
  68. 'Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
  69. 'Public Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
  70. 'Public Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
  71. 'Public Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
  72. 'Public Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
  73. 'Public Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
  74. 'Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  75. 'Public Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
  76. 'Public Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
  77. Public Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
  78. 'Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
  79. 'Public Declare Function PatBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal dwRop As Long) As Long
  80. 'Public Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
  81. 'Public Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long
  82. 'Public Declare Function GetBkColor Lib "gdi32" (ByVal hdc As Long) As Long
  83. 'Public Declare Function GetTextColor Lib "gdi32" (ByVal hdc As Long) As Long
  84. 'Public Declare Function SelectPalette Lib "gdi32" (ByVal hdc As Long, ByVal hPalette As Long, ByVal bForceBackground As Long) As Long
  85. 'Public Declare Function RealizePalette Lib "gdi32" (ByVal hdc As Long) As Long
  86. 'Public Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
  87. Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSrc As Any, ByVal ByteLen As Long)
  88. 'Public Declare Function CreateHalftonePalette Lib "gdi32" (ByVal hdc As Long) As Long
  89.  
  90. #If UNICODE Then
  91.     Public Declare Function DrawState Lib "user32" Alias "DrawStateW" (ByVal hDC As Long, ByVal hBrush As Long, ByVal lpDrawStateProc As Long, ByVal lParam As Long, ByVal wParam As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal n3 As Long, ByVal n4 As Long, ByVal un As Long) As Long
  92.     Public Declare Function SendMessage Lib "user32" Alias "SendMessageW" (ByVal hwnd As Long, ByVal uMgs As Long, ByVal wParam As Long, lParam As Any) As Long
  93.     Public Declare Function CreateWindowEX Lib "user32" Alias "CreateWindowExW" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
  94.     Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcW" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal MSG As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  95.     Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongW" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Any) As Long
  96.     Public Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundW" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
  97.     Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongW" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  98. #Else
  99.     Public Declare Function DrawState Lib "user32" Alias "DrawStateA" (ByVal hDC As Long, ByVal hBrush As Long, ByVal lpDrawStateProc As Long, ByVal lParam As Long, ByVal wParam As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal n3 As Long, ByVal n4 As Long, ByVal un As Long) As Long
  100.     Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal uMgs As Long, ByVal wParam As Long, lParam As Any) As Long
  101.     Public Declare Function CreateWindowEX Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
  102.     Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal MSG As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  103.     Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Any) As Long
  104.     Public Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
  105.     Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  106. #End If
  107. Public Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
  108. Public Declare Sub InitCommonControls Lib "Comctl32.dll" ()
  109. Public Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
  110. Public Declare Function ReleaseCapture Lib "user32" () As Long
  111. Public Declare Function OleTranslateColor Lib "oleaut32.dll" (ByVal lOleColor As Long, ByVal lHPalette As Long, lColorRef As Long) As Long
  112.  
  113. 'Misc Constants
  114. Public Const H_MAX As Long = &HFFFFFFFF + 1
  115. Public Const TOOLTIPS_CLASS As String = "tooltips_class32"
  116. Public Const WS_EX_TOPMOST = &H8&
  117. Public Const CW_USEDEFAULT  As Long = &H80000000
  118. Public Const glSUNKEN_OFFSET = 1
  119. Public Const GDI_ERROR = &HFFFFFFFF
  120.  
  121. 'Windows Messages
  122. Public Const WM_CANCELMODE = &H1F
  123.  
  124. 'Resource String Indexes
  125. Public Const giINVALID_PIC_TYPE As Integer = 10
  126.  
  127. 'Get Windows Long Constants
  128. Public Const GWL_USERDATA = (-21)
  129. Public Const GWL_WNDPROC = (-4)
  130.  
  131. ''Draw State constants
  132. ''Image type
  133. 'Public Const DST_ICON = &H3&
  134. 'Public Const DST_BITMAP = &H4&
  135. ''State type
  136. 'Public Const DSS_DISABLED = &H20&
  137.  
  138. ''Raster Operation Codes
  139. 'Public Const PSDPxax = &HB8074A
  140. 'Public Const DSna = &H220326 '0x00220326
  141.  
  142. 'System colors
  143. Public Const COLOR_BTNFACE = 15
  144. Public Const COLOR_BTNSHADOW = 16
  145. Public Const COLOR_BTNHIGHLIGHT = 20
  146.  
  147. 'Messages to relay to ToolTip
  148. Public Const WM_USER = &H400
  149. Public Const WM_NOTIFY = &H4E
  150. Public Const WM_MOUSEMOVE = &H200
  151. Public Const WM_LBUTTONDOWN = &H201
  152. Public Const WM_LBUTTONUP = &H202
  153. Public Const WM_RBUTTONDOWN = &H204
  154. Public Const WM_RBUTTONUP = &H205
  155. Public Const WM_MBUTTONDOWN = &H207
  156. Public Const WM_MBUTTONUP = &H208
  157.  
  158. 'ToolTip style
  159. Public Const TTF_IDISHWND = &H1
  160.  
  161. 'Tool Tip messages
  162. Public Const TTM_ACTIVATE = (WM_USER + 1)
  163. #If UNICODE Then
  164.     Public Const TTM_ADDTOOLW = (WM_USER + 50)
  165.     Public Const TTM_ADDTOOL = TTM_ADDTOOLW
  166. #Else
  167.     Public Const TTM_ADDTOOLA = (WM_USER + 4)
  168.     Public Const TTM_ADDTOOL = TTM_ADDTOOLA
  169. #End If
  170. Public Const TTM_RELAYEVENT = (WM_USER + 7)
  171.  
  172. 'ToolTip Notification
  173. Public Const TTN_FIRST = (H_MAX - 520&)
  174. #If UNICODE Then
  175.     Public Const TTN_NEEDTEXTW = (TTN_FIRST - 10&)
  176.     Public Const TTN_NEEDTEXT = TTN_NEEDTEXTW
  177. #Else
  178.     Public Const TTN_NEEDTEXTA = (TTN_FIRST - 0&)
  179.     Public Const TTN_NEEDTEXT = TTN_NEEDTEXTA
  180. #End If
  181.  
  182. 'Misc ToolTip
  183. Public Const LPSTR_TEXTCALLBACK As Long = -1
  184.  
  185. ' Border flags
  186. Public Const BF_LEFT As Long = &H1
  187. Public Const BF_TOP As Long = &H2
  188. Public Const BF_RIGHT As Long = &H4
  189. Public Const BF_BOTTOM As Long = &H8
  190. Public Const BF_RECT As Long = (BF_LEFT Or BF_TOP Or BF_RIGHT Or BF_BOTTOM)
  191.  
  192. Public Const BF_SOFT As Long = &H1000      ' For softer buttons
  193.  
  194. Public Const SND_SYNC = 0
  195. Public Const EVENT_MENU_COMMAND = "MenuCommand"
  196. Public Const EVENT_MENU_POPUP = "MenuPopup"
  197.  
  198.  
  199. ''Button States
  200. 'Public Const giFLATTENED As Integer = 0
  201. 'Public Const giRAISED As Integer = 1
  202. 'Public Const giSUNKEN As Integer = 3
  203. 'Public Const giDISABLED As Integer = 4
  204.  
  205. 'VB Errors
  206. Public Const giOBJECT_VARIABLE_NOT_SET As Integer = 91
  207. Public Const giDLL_FUNCTION_NOT_FOUND As Integer = 453
  208.  
  209. 'Windows Errors
  210. Public Const ERROR_CALL_NOT_IMPLEMENTED As Long = 120
  211.  
  212.  
  213. Public gHWndToolTip As Long                 'Hwnd of Tooltip created by this object
  214. Public gbToolTipsInstanciated As Boolean    'If true the ToolTip class window has been created
  215. Public glToolsCount As Long                 'The number of controls using tool tips
  216.                                             
  217. #If DEBUGSUBCLASS Then
  218.     Public goWindowProcHookCreator As Object
  219. #End If
  220.  
  221. Public Function SubWndProc(ByVal hwnd As Long, ByVal MSG As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  222.     '-------------------------------------------------------------------------
  223.     'Purpose:   Address used for subclassing.  Calls instance of uctlSoftButton
  224.     '           whose hWnd is stored in USERDATA of window matching passed hWnd
  225.     '-------------------------------------------------------------------------
  226.     On Error Resume Next
  227.     SubWndProc = ConvertUserDataToPopupCommand(hwnd).WindowProc(hwnd, MSG, wParam, lParam)
  228. End Function
  229.  
  230. Private Function ConvertUserDataToPopupCommand(hwnd As Long) As axDataButton
  231.     '-------------------------------------------------------------------------
  232.     'Purpose:   Gets the hWnd of a uctlPopupCommand object, and converts it
  233.     '           to a reference to the uctlPopupCommand object without increasing
  234.     '           VB's ref count of that object
  235.     '-------------------------------------------------------------------------
  236.     Dim Obj As axDataButton
  237.     Dim pObj As Long
  238.     pObj = GetWindowLong(hwnd, GWL_USERDATA)
  239.     CopyMemory Obj, pObj, 4
  240.     Set ConvertUserDataToPopupCommand = Obj
  241.     CopyMemory Obj, 0&, 4
  242. End Function
  243.  
  244.  
  245.